package com.ktgj.customer.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.customer.domain.MallProductSpec;
import com.ktgj.customer.service.IMallProductSpecService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 商品规格Controller
 * 
 * @author ruoyi
 * @date 2022-05-30
 */
@RestController
@RequestMapping("/spec")
public class MallProductSpecController extends BaseController
{
    @Autowired
    private IMallProductSpecService mallProductSpecService;

    /**
     * 查询商品规格列表
     */
    @PreAuthorize(hasPermi = "customer:spec:list")
    @GetMapping("/list")
    public TableDataInfo list(MallProductSpec mallProductSpec)
    {
        startPage();
        List<MallProductSpec> list = mallProductSpecService.selectMallProductSpecList(mallProductSpec);
        return getDataTable(list);
    }

    /**
     * 导出商品规格列表
     */
    @PreAuthorize(hasPermi = "customer:spec:export")
    @Log(title = "商品规格", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MallProductSpec mallProductSpec) throws IOException
    {
        List<MallProductSpec> list = mallProductSpecService.selectMallProductSpecList(mallProductSpec);
        ExcelUtil<MallProductSpec> util = new ExcelUtil<MallProductSpec>(MallProductSpec.class);
        util.exportExcel(response, list, "商品规格数据");
    }

    /**
     * 获取商品规格详细信息
     */
    @PreAuthorize(hasPermi = "customer:spec:query")
    @GetMapping(value = "/{productSpecId}")
    public AjaxResult getInfo(@PathVariable("productSpecId") Long productSpecId)
    {
        return AjaxResult.success(mallProductSpecService.selectMallProductSpecById(productSpecId));
    }

    /**
     * 新增商品规格
     */
    @PreAuthorize(hasPermi = "customer:spec:add")
    @Log(title = "商品规格", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallProductSpec mallProductSpec)
    {
        return toAjax(mallProductSpecService.insertMallProductSpec(mallProductSpec));
    }

    /**
     * 修改商品规格
     */
    @PreAuthorize(hasPermi = "customer:spec:edit")
    @Log(title = "商品规格", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallProductSpec mallProductSpec)
    {
        return toAjax(mallProductSpecService.updateMallProductSpec(mallProductSpec));
    }

    /**
     * 删除商品规格
     */
    @PreAuthorize(hasPermi = "customer:spec:remove")
    @Log(title = "商品规格", businessType = BusinessType.DELETE)
	@DeleteMapping("/{productSpecIds}")
    public AjaxResult remove(@PathVariable Long[] productSpecIds)
    {
        return toAjax(mallProductSpecService.deleteMallProductSpecByIds(productSpecIds));
    }
}
